import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'
let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    console.log(_this.orderType, 'orderType')
    this.all = []
    let publicArr = [
      {
        title: `${_this.orderType}单编号`,
        field: 'orderCode',
        minWidth: 160
      },
      {
        title: `${_this.orderType}房源`,
        field: 'roomName',
        minWidth: 130
      },
      {
        field: 'customerName',
        title: '客户姓名',
        minWidth: 150
      },
      {
        title: '客户手机号',
        field: 'customerPhone',
        minWidth: 150
      },
      {
        field: 'counselorName',
        title: '归属顾问',
        minWidth: 130
      },
      {
        field: 'productName',
        title: '所属产品',
        minWidth: 150,
        cell: {
          text: {
            lineClamp: 2,
            webkitBoxOrient: 'vertical',
            display: '-webkit-box',
            whiteSpace: 'inherit'
          }
        }
      },
      {
        title: '当前面积(㎡)',
        field: 'currentAdjustArea',
        minWidth: 150
      },
      {
        title: `当前${_this.orderType}总价(元)`,
        field: 'currentAdjustPrice',
        minWidth: 140
      },
      {
        title: '调整后面积(㎡)',
        field: 'afterAdjustArea',
        minWidth: 150
      },
      {
        title: `调整后${_this.orderType}总价(元)`,
        field: 'afterAdjustPrice',
        minWidth: 150
      },
      {
        title: '调整面积差(㎡)',
        field: 'areaDV',
        minWidth: 150,
        slots: {
          default: (params, h) => {
            let color = params.row.areaDV > 0 ? '#D9001B' : params.row.areaDV < 0 ? '#70B603' : '#515a6e'

            return table.cell.text(h, {
              value: params.row.areaDV > 0 ? '+' + params.row.areaDV : params.row.areaDV,
              color: color
            })
          }
        }
      },
      {
        title: '调整总价差(元)',
        field: 'priceDV',
        minWidth: 150,
        slots: {
          default: (params, h) => {
            let color = params.row.priceDV > 0 ? '#D9001B' : params.row.priceDV < 0 ? '#70B603' : '#515a6e'

            return table.cell.text(h, {
              value: params.row.priceDV > 0 ? '+' + params.row.priceDV : params.row.priceDV,
              color: color
            })
          }
        }
      }
    ]

    let subArr = [
      {
        field: 'subscriptionDate',
        minWidth: 150,
        title: '认购日期'
      },
      {
        title: '认购人',
        field: 'contractorName',
        minWidth: 130
      },
      {
        title: '认购状态',
        field: 'showStatus',
        minWidth: 130,
        cell: (item) => {
          return {
            text: {
              type: 'dict',
              key: 'subscriptionStatus',
              color: item.showStatus == 2 ? '#D9001B' : '#515a6e'
            }
          }
        }
      }
    ]
    let contractArr = [
      {
        title: '调整后新增回款金额(元)',
        field: 'priceDV',
        minWidth: 200,
        slots: {
          default: (params, h) => {
            let color = params.row.priceDV > 0 ? '#D9001B' : params.row.priceDV < 0 ? '#70B603' : '#515a6e'
            return table.cell.text(h, {
              value: params.row.priceDV > 0 ? '+' + params.row.priceDV : params.row.priceDV,
              color: color
            })
          }
        }
      },
      {
        title: '签约日期',
        field: 'contractDate',
        minWidth: 180
      },
      {
        title: '签约人',
        field: 'contractorName',
        minWidth: 150
      },
      {
        title: '签约状态',
        field: 'showStatus',
        minWidth: 150,
        cell: (item) => {
          return {
            text: {
              type: 'dict',
              key: 'status',
              color: item.showStatus == 10102 ? '#D9001B' : '#515a6e'
            }
          }
        }
      }
    ]
    if (_this.orderType == '认购') {
      this.all.push(...publicArr, ...subArr)
    } else if (_this.orderType == '签约') {
      this.all.push(...publicArr, ...contractArr)
    }
  }
}

export default Column
